/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tecbooks;

import javax.swing.JOptionPane;
import java.awt.Color;
/**
 *
 * @author ferreira
 */
public class Devolucao extends javax.swing.JFrame {

    /**
     * Creates new form Devolucao
     */
    public Devolucao() {
        initComponents();
        setTitle("Devolução");
        this.getContentPane().setBackground(Color.pink);      
        this.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblIdClienteDevolucao = new javax.swing.JLabel();
        txtIdClienteDevolucao = new javax.swing.JFormattedTextField();
        lblIdLivroDevolucao = new javax.swing.JLabel();
        txtIdLivroDevolucao = new javax.swing.JFormattedTextField();
        lblDataEntrega = new javax.swing.JLabel();
        lblDataDevolucao = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        btnLimpar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();
        lblMensagem = new javax.swing.JLabel();
        lblAviso1 = new javax.swing.JLabel();
        lblAviso2 = new javax.swing.JLabel();
        cmbDiaDevolucaoPrevista = new javax.swing.JComboBox();
        cmbMesDevolucaoPrevista = new javax.swing.JComboBox();
        cmbAnoDevolucaoPrevista = new javax.swing.JComboBox();
        cmbDiaDevolucao = new javax.swing.JComboBox();
        cmbMesDevolucao = new javax.swing.JComboBox();
        cmbAnoDevolucao = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblIdClienteDevolucao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblIdClienteDevolucao.setText("ID Cliente*:");

        txtIdClienteDevolucao.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        txtIdClienteDevolucao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdClienteDevolucaoActionPerformed(evt);
            }
        });
        txtIdClienteDevolucao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtIdClienteDevolucaoKeyTyped(evt);
            }
        });

        lblIdLivroDevolucao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblIdLivroDevolucao.setText("ID Livro*:");

        txtIdLivroDevolucao.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        txtIdLivroDevolucao.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtIdLivroDevolucaoKeyTyped(evt);
            }
        });

        lblDataEntrega.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblDataEntrega.setText("Data prevista para entrega:");

        lblDataDevolucao.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblDataDevolucao.setText("Data de devolução:");

        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        btnLimpar.setText("Limpar");
        btnLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimparActionPerformed(evt);
            }
        });

        btnSair.setText("Sair");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });

        lblMensagem.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblMensagem.setForeground(new java.awt.Color(255, 0, 51));

        lblAviso1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblAviso1.setForeground(new java.awt.Color(255, 0, 0));

        lblAviso2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        lblAviso2.setForeground(new java.awt.Color(255, 0, 0));

        cmbDiaDevolucaoPrevista.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        cmbMesDevolucaoPrevista.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }));

        cmbAnoDevolucaoPrevista.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        cmbDiaDevolucao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        cmbDiaDevolucao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbDiaDevolucaoActionPerformed(evt);
            }
        });

        cmbMesDevolucao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }));

        cmbAnoDevolucao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMensagem, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(26, 26, 26)
                        .addComponent(btnLimpar)
                        .addGap(31, 31, 31)
                        .addComponent(btnSair)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblDataDevolucao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmbDiaDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)
                        .addComponent(cmbMesDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(cmbAnoDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblDataEntrega)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbDiaDevolucaoPrevista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(23, 23, 23)
                        .addComponent(cmbMesDevolucaoPrevista, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(20, 20, 20)
                        .addComponent(cmbAnoDevolucaoPrevista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblIdClienteDevolucao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtIdClienteDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblAviso1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblIdLivroDevolucao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(lblAviso2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtIdLivroDevolucao, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblIdClienteDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtIdClienteDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblAviso1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtIdLivroDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblIdLivroDevolucao))
                .addGap(11, 11, 11)
                .addComponent(lblAviso2, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblDataEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cmbDiaDevolucaoPrevista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cmbMesDevolucaoPrevista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(cmbAnoDevolucaoPrevista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDataDevolucao)
                    .addComponent(cmbDiaDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbMesDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbAnoDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLimpar)
                    .addComponent(btnSair)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(lblMensagem, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtIdClienteDevolucaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdClienteDevolucaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdClienteDevolucaoActionPerformed

    private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimparActionPerformed
        // TODO add your handling code here:
        cmbAnoDevolucao.setSelectedIndex(0);
        cmbMesDevolucao.setSelectedIndex(0);
        cmbDiaDevolucao.setSelectedIndex(0);
        cmbAnoDevolucaoPrevista.setSelectedIndex(0);
        cmbMesDevolucaoPrevista.setSelectedIndex(0);
        cmbDiaDevolucaoPrevista.setSelectedIndex(0);
        txtIdClienteDevolucao.setText("");
        txtIdLivroDevolucao.setText("");
        
        
    }//GEN-LAST:event_btnLimparActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        // TODO add your handling code here:
        dispose();
        TelaPrincipal tela = new TelaPrincipal();
        tela.setVisible(true);
    }//GEN-LAST:event_btnSairActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
      if(cmbAnoDevolucao.getSelectedItem().equals("  ")||cmbAnoDevolucaoPrevista.getSelectedItem().equals("  ") || cmbMesDevolucao.getSelectedItem().equals("  ")||cmbMesDevolucaoPrevista.getSelectedItem().equals("  ")||
              cmbDiaDevolucao.getSelectedItem().equals("  ")||cmbDiaDevolucaoPrevista.getSelectedItem().equals("  ")|| txtIdClienteDevolucao.getText().isEmpty() || txtIdLivroDevolucao.getText().isEmpty()){
            lblMensagem.setText("Preencha os campos obrigatórios!");
        }
        else{
            JOptionPane.showMessageDialog(null, "Devolução realizada com sucesso!");
            dispose();
            TelaPrincipal tela = new TelaPrincipal();
            tela.setVisible(true);
        }       
        
          // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void txtIdClienteDevolucaoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdClienteDevolucaoKeyTyped
     String numeros = "0123456789";
        if(!numeros.contains(evt.getKeyChar()+"") && (int)evt.getKeyChar() != 8){
            evt.consume();
            lblAviso1.setText("Por favor, informe apenas números!");
        }
        else{
           lblAviso1.setText("");
        }        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdClienteDevolucaoKeyTyped

    private void txtIdLivroDevolucaoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtIdLivroDevolucaoKeyTyped
     String numeros = "0123456789";
        if(!numeros.contains(evt.getKeyChar()+"") && (int)evt.getKeyChar() != 8){
            evt.consume();
            lblAviso2.setText("Por favor, informe apenas números!");
        }
        else{
           lblAviso2.setText("");
        }        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdLivroDevolucaoKeyTyped

    private void cmbDiaDevolucaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbDiaDevolucaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cmbDiaDevolucaoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Devolucao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Devolucao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Devolucao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Devolucao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Devolucao().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLimpar;
    private javax.swing.JButton btnSair;
    private javax.swing.JComboBox cmbAnoDevolucao;
    private javax.swing.JComboBox cmbAnoDevolucaoPrevista;
    private javax.swing.JComboBox cmbDiaDevolucao;
    private javax.swing.JComboBox cmbDiaDevolucaoPrevista;
    private javax.swing.JComboBox cmbMesDevolucao;
    private javax.swing.JComboBox cmbMesDevolucaoPrevista;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel lblAviso1;
    private javax.swing.JLabel lblAviso2;
    private javax.swing.JLabel lblDataDevolucao;
    private javax.swing.JLabel lblDataEntrega;
    private javax.swing.JLabel lblIdClienteDevolucao;
    private javax.swing.JLabel lblIdLivroDevolucao;
    private javax.swing.JLabel lblMensagem;
    private javax.swing.JFormattedTextField txtIdClienteDevolucao;
    private javax.swing.JFormattedTextField txtIdLivroDevolucao;
    // End of variables declaration//GEN-END:variables
}
